import { history } from 'umi';
const timeOut = 10 * 60 * 1000; // 设置超时时间：30分钟
const interValTime = 5 * 60 * 1000;

const updateHandleTime = () => {
  window.document.onmouseover = () => {
    sessionStorage.setItem('lastTime', new Date().getTime());
  };
};

const checkTimeOut = () => {
  updateHandleTime();
  window.setInterval(() => {
    let currentTime = new Date().getTime();
    let lastTime = sessionStorage.getItem('lastTime');
    if (currentTime - lastTime > timeOut) {
      sessionStorage.removeItem('lastTime');
      if (!location.href.includes('login')) {
        history.push('/login');
      }
    } else {
      console.log('无超时');
    }
  }, interValTime);
};

export default checkTimeOut;
